package com.ruoyi.web.controller.interview;


import com.alibaba.fastjson2.JSONArray;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.interview.domain.IntervFile;
import com.ruoyi.interview.service.IIntervFileService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;

/**
 * 文件信息Controller
 *
 */
@RestController
@RequestMapping("/interview/file")
public class IntervFileController extends BaseController
{
    @Autowired
    private IIntervFileService intervFileService;

    /**
     * 查询文件信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:file:list')")
    @GetMapping("/list")
    public TableDataInfo list(IntervFile intervFile)
    {
        startPage();
        List<IntervFile> list = intervFileService.selectIntervFileList(intervFile);
        return getDataTable(list);
    }

    /**
     * 导出文件信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:file:export')")
    @Log(title = "文件信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, IntervFile intervFile)
    {
        List<IntervFile> list = intervFileService.selectIntervFileList(intervFile);
        ExcelUtil<IntervFile> util = new ExcelUtil<IntervFile>(IntervFile.class);
        util.exportExcel(response, list, "文件信息数据");
    }

    /**
     * 获取文件信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:file:query')")
    @GetMapping(value = "/{fileId}")
    public AjaxResult getInfo(@PathVariable("fileId") Long fileId)
    {
        return AjaxResult.success(intervFileService.selectIntervFileByFileId(fileId));
    }

    /**
     * 新增文件信息
     */
    @PreAuthorize("@ss.hasPermi('system:file:add')")
    @Log(title = "文件信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody IntervFile intervFile)
    {
        return toAjax(intervFileService.insertIntervFile(intervFile));
    }

    /**
     * 修改文件信息
     */
    @PreAuthorize("@ss.hasPermi('system:file:edit')")
    @Log(title = "文件信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody IntervFile intervFile)
    {
        return toAjax(intervFileService.updateIntervFile(intervFile));
    }

    /**
     * 删除文件信息
     */
    @PreAuthorize("@ss.hasPermi('system:file:remove')")
    @Log(title = "文件信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{fileIds}")
    public AjaxResult remove(@PathVariable Long[] fileIds)
    {
        return toAjax(intervFileService.deleteIntervFileByFileIds(fileIds));
    }


    /**
     * 根据id查询多个文件信息
     */
    @PreAuthorize("@ss.hasPermi('system:file:query')")
    @Log(title = "文件信息", businessType = BusinessType.OTHER)
    @GetMapping("/s/{fileIds}")
    public AjaxResult selectByIds(@Param("array") @PathVariable Long[] fileIds)
    {
        return AjaxResult.success(intervFileService.selectIntervFileByFileIds(fileIds));
    }






}
